package com.knife.lov.api.controller.v1;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.knife.lov.app.service.CodeValueService;
import com.knife.lov.domain.entity.KnifeCodeValue;
import com.knife.oauth.tenant.annonations.KnifeTenant;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @author： 76875
 * @date： 2022/4/15 星期五 18:00
 * @description：
 * @modifiedBy：
 * @version: 1.0
 */
@RestController("v1.CodeValueController")
@RequestMapping("/v1/{organizationId}/code-value")
@KnifeTenant
public class CodeValueController {

    @Resource
    private CodeValueService codeValueService;

    /**
     * 查询代码列表
     */
    @GetMapping
    public Page<KnifeCodeValue> selectCodeValuePage(@PathVariable Long organizationId, KnifeCodeValue knifeCode, Page<KnifeCodeValue> pageRequest) {
        knifeCode.setTenantId(organizationId);
        return codeValueService.selectCodeValuePage(knifeCode, pageRequest);
    }

    /**
     * 查询代码列表
     */
    @GetMapping("/code")
    public List<KnifeCodeValue> selectCodeValueByCode(@PathVariable Long organizationId,@RequestParam String knifeCode) {
        return codeValueService.selectCodeValueByCode(organizationId, knifeCode);
    }

    /**
     * 保存或更新代码
     */
    @PostMapping
    public KnifeCodeValue saveAndUpdateCodeValue(@PathVariable Long organizationId,@RequestBody KnifeCodeValue knifeCode) {
        knifeCode.setTenantId(organizationId);
        return codeValueService.saveAndUpdateCodeValue(knifeCode);
    }

    /**
     * 删除代码
     */
    @DeleteMapping
    public KnifeCodeValue deleteCodeValue(@PathVariable Long organizationId,@RequestBody KnifeCodeValue knifeCode) {
        knifeCode.setTenantId(organizationId);
        return codeValueService.deleteCodeValue(knifeCode);
    }
}
